package com.xh.pmo.actions;

import java.util.ArrayList;
import java.util.List;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionContext;
import com.sun.org.apache.bcel.internal.generic.ACONST_NULL;
import com.xh.pmo.base.ModelDrivenBaseAction;
import com.xh.pmo.domain.Project;
import com.xh.pmo.domain.Team;
import com.xh.pmo.domain.Team_User;
import com.xh.pmo.domain.User;

@Controller
@Scope("prototype")
public class ProjectAction extends ModelDrivenBaseAction<Project> {
	/**
	 * 
	 */
	private static final long serialVersionUID = 6770915960605135682L;

	public String list() {
		
		User user = getCurrentUser();
		
		List<Team_User> teamUserList = team_userService.findTeamByUser(user);
		List<Long> teamList = new ArrayList<Long>();
		
		for(Team_User tu : teamUserList) {
			teamList.add(tu.getTeam().getId());
		}
		List<Project> projectList = projectService.findByTeams(teamList);
		ActionContext.getContext().put("projectList", projectList);
		
		return "list";
	}
	
	public String showProject () {
		
		
		Project project = projectService.getById(model.getId());
		ActionContext.getContext().put("project", project);
		return "showProject";
	}
	
	
}
